package com.crazymaker.springcloud.reactive.rpc;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.util.Map;

@Slf4j
public class MockRpcMethodHandler implements RpcMethodHandler {

    final String contextPath;

    final String url;

    public MockRpcMethodHandler(String contextPath, String url) {
        this.contextPath = contextPath;
        this.url = url;
    }

    @Override
    public Object invoke(Object[] args) throws Throwable {
        RestTemplate restTemplate = new RestTemplate();

        String restUrl = "http://localhost:8080" + contextPath + url;
        log.info("restUrl = {}", restUrl);

        return restTemplate.getForEntity(new URI(restUrl), Map.class);
    }
}
